using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace Charisma
{
    public class EntityMemberConfigurator
    {
        internal MemberInfo Member;
        internal string Name;
        internal bool IsIgnored;

        protected EntityMemberConfigurator(MemberInfo member)
        {
            Contract.Requires(member != null);
            Member = member;
        }
    }

    public class EntityMemberConfigurator<T, TValue> : EntityMemberConfigurator
    {
        public EntityMemberConfigurator(EntityConfigurator<T> owner, MemberInfo member)
            : base(member)
        {
            Contract.Requires(owner != null);
            Owner = owner;
        }

        private EntityConfigurator<T> Owner { get; set; }

        public EntityMemberConfigurator<T, TValue> HasName(string name)
        {
            Contract.Requires(!String.IsNullOrEmpty(name));

            Name = name;
            return this;
        }

        public EntityMemberConfigurator<T, T2> Map<T2>(Expression<Func<T, T2>> expression)
        {
            return Owner.Map(expression);
        }

        public EntityConfigurator<T> Ignore<T2>(Expression<Func<T, T2>> expression)
        {
            return Owner.Ignore(expression);
        }

        public EntityConfigurator<T> Ignore()
        {
            IsIgnored = true;
            return Owner;
        }
    }
}